package group2.beans;

import group2.core.database.DatabaseUtil;
import group2.core.entities.Post;
import java.io.Serializable;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;


/**
 * Used for showing an previews of posts.
 * 
 * @author cnilsson
 */
@ManagedBean
@ViewScoped
public class StartViewBean implements Serializable {

    private List<Post> postList;
    private final static int SHOW_AMOUNT = 10;

    public List<Post> getPostList() {
        return postList;
    }
    
    private void populatePosts() {
    //Returns all the posts sorted by date.
        this.postList = DatabaseUtil.getInstance().getLatestPosts(SHOW_AMOUNT);
    }

    public void showAllPosts() {
        this.postList = DatabaseUtil.getInstance().getLatestPosts(-1);
    }

    /** Creates a new instance of StartViewBean */
    public StartViewBean() {
        populatePosts();
    }
}
